package shooting.motion.tween
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.geom.Point;
	
	public class PointTweener extends EventDispatcher
	{
		private var startPt:Point;
		private var targetPt:Point;
		private var retPt:Point = new Point;
		private var steps:uint;
		private var stepCount:uint;
		private var easingFunc:Function;
		private var dist_x:Number;
		private var dist_y:Number;
		
		public function PointTweener()
		{
		}
		public function setTtween( pt:Point, target:Point, step:uint, easing:Function):void
		{
			startPt = pt;
			targetPt = target;
			steps = step; 
			easingFunc = easing;
			stepCount = 0;
			dist_x = targetPt.x - startPt.x;
			dist_y = targetPt.y - startPt.y;
		}
		public function tweenStep():Point
		{
			if( stepCount >= steps) return targetPt;
			stepCount++;
			retPt.x = easingFunc(stepCount, startPt.x, dist_x, steps );
			retPt.y = easingFunc(stepCount, startPt.y, dist_y, steps );
			if( stepCount >= steps)
			{
				dispatchEvent( new Event( Event.COMPLETE ));
			}
			return retPt;
		}

	}
}